#ifndef SDBAD_H
#define SDBAD_H

#include <vector>
#include <set>
#include <math.h>
#include <iostream>
#include "../src/chipmunk.h"
#include "sdObject.h"
#include "sdTimed.h"
#include "sdBadChunk.h"

//Class Bad
//Represents an enemy ship
class sdBad : public sdObject {
private:
    cpFloat hp_; //Current hitpoints
    cpFloat maxHp_; //Maximum hitpoints
    
   	sdObject* target_; //It's current target

	bool killed_; //If it has "died" yet

	cpFloat deltaW_; //Turning speed, actually a factor(see implementation)
	cpFloat forwardsForce_; //How fast they move forwards

public:
	//Constructs a mass 10 enemy with the given parameters
    inline sdBad(int hp, int maxHp, cpFloat velocity, cpFloat turn, cpVect pos) : sdObject(cpBodyNew(0, 0)), hp_(hp), maxHp_(maxHp), target_(NULL) {
        setMass(10.0);
        getBody().p = pos;
    	
    	setDeltaW(turn);
    	setForwardsForce(velocity);

    	addCircleShape(0.0, 20.0, cpvzero, 3);

		killed_ = false;
    }
   
    void move(const cpVect& direction); //move in the specified direction
    void turn(const cpVect& direction); //turn to face this direction
    void follow(); //Use ai to attempt to collide with target
    
    void getChunks(std::set<sdBadChunk*>* chunks); //Get the chunks that spawn on death
    
    inline void takeDamage(cpFloat damage) {hp_ -= damage;} //Take damage damage
    inline cpFloat getHp() {return hp_;}
    inline cpFloat getMaxHp() {return maxHp_;}
    inline bool dead() {return hp_ <= 0;}

	inline void kill() {killed_ = true;}
	inline bool killed() {return killed_;}
    
    inline void setTarget(sdObject* target) {target_ = target;}
    inline sdObject* getTarget() {return target_;}
          
    inline void setDeltaW(cpFloat deltaW) {deltaW_ = deltaW;}
    inline cpFloat getDeltaW() {return deltaW_;}
    
 	inline void setForwardsForce(cpFloat forwardsForce) {forwardsForce_ = forwardsForce;}
	inline cpFloat getForwardsForce() {return forwardsForce_;}
};

#endif
